package mc2014.hackerthon.Adapters;

import java.util.ArrayList;

import android.R;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.GridView;

public class MainPagerAdapter extends PagerAdapter 
{

	private Context context;
	private ArrayList<GridView> GridviewList;
	private CustomGridAdapter customGridAdapter;
	public MainPagerAdapter(Context con)
	{
		context = con;
		GridviewList = new ArrayList<GridView>();
	}
	@Override
	public int getCount() 
	{
		return GridviewList == null ? 0:GridviewList.size();
	}

	
	@Override
	public Object instantiateItem(View pager, int position) 
    {  
        //해당 포지션의 아이템 뷰를 생성한다
		View v = GridviewList.get(position);
		((ViewPager)pager).addView(v);
		return v;
        
    }
	
	@Override 
	public void destroyItem(View pager, int position, Object view)
	{
	    ((ViewPager)pager).removeView((View)view);
    }
	
	public void addItem(int img_id,String groupname) 
	{
		customGridAdapter.addItem(img_id,groupname);
		
	}
	
	public void addGrid()
	{
		GridView addGridview = new GridView(context);
		addGridview.setColumnWidth(800);
		addGridview.setNumColumns(3);
		addGridview.setVerticalSpacing(4);
		
		customGridAdapter = new CustomGridAdapter(context);
		addGridview.setAdapter(customGridAdapter);
		GridviewList.add(addGridview);
		notifyDataSetChanged();
	}
	
	 @Override public boolean isViewFromObject(View view, Object obj) { return view == obj; }
	

}
